﻿namespace Web.Control.Member.Public
{
    using System;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using System.Text.RegularExpressions;
    using Lx.Web.Common.UI;
    using Lx.Web.Common.ControlsUI;
    using System.Collections;
    using System.IO;
    using BLF.WWW_WWW.Contact;
    using Model.WWW_User;
    using BLF;
    using System.Collections.Generic;
    using Model.WWW_User.User;

    public class StuProfile : BaseControl
    {
        protected string mymemberno = "";
        protected string memberno = "";
        protected ArrayList arrlist = new ArrayList();
        protected List<MemberSimpleModel> msmlist = new List<MemberSimpleModel>();
        protected UserProfileModel userInfo = new UserProfileModel();
        protected List<int> intlist = new List<int>();
        protected Repeater rptLastEvent;
        protected Repeater rptqm;
        protected Repeater rptMemberList;
        protected Repeater rptMember2List;
        protected Repeater userComment;
        protected List<Model.WWW_User.User.UserEvents> uelist = new List<UserEvents>();
        /// <summary>
        /// 当前用户与该会员关系1好友，2已是联系人，0无int、
        /// </summary>
        protected int UserRelation = -1;
        protected bool IsAgreeContInfo=false;
        protected override void OnLoad(EventArgs e)
        {
            
            if (Request["uid"] != null && !String.IsNullOrEmpty(Request["uid"].ToString()))
            {
                memberno = Request["uid"].ToString();
                mymemberno = HttpContext.Current.User.Identity.Name;
            }
            else
            {   memberno = HttpContext.Current.User.Identity.Name;
                if (memberno == "")
                {
                    Page.Response.Redirect("/user/login.htm?ReturnUrl=" + Page.Request.Url.AbsoluteUri);
                    return;
                }

                mymemberno = memberno;

            }
           arrlist=BLF.WWW_User.Users.User.GetUserPuProfile(memberno, mymemberno);
           if (arrlist == null)
           {
               Response.End();
           }
           if (arrlist.Count == 1)
           {
               Server.Transfer(string.Format("/public/TProfile.htm?uid={0}", memberno), false);
           }
           intlist = arrlist[2] as List<int>;
           UserRelation = (int)arrlist[0];
           msmlist = arrlist[7] as List<MemberSimpleModel>;
           userInfo = arrlist[1] as UserProfileModel;
           uelist = arrlist[3] as List<Model.WWW_User.User.UserEvents>;
            if (rptMemberList != null)
            {
                rptMemberList.DataSource = arrlist[4];
                rptMemberList.DataBind();
            }
            if (rptMember2List != null)
            {
                rptMember2List.DataSource = msmlist;
                rptMember2List.DataBind();
            }
            if (rptLastEvent != null)
            {
                rptLastEvent.DataSource = arrlist[3];
                rptLastEvent.DataBind();
            }
            if (userComment != null)
            {
                userComment.DataSource = arrlist[6];
                userComment.DataBind();
            }
            if (rptqm != null )
            {

                rptqm.DataSource = arrlist[5];
                rptqm.DataBind();

            }
            if (userInfo.WhoAddComment == "0" || (userInfo.WhoAddComment == "1" && HttpContext.Current.User.Identity.Name != "") || (userInfo.WhoAddComment == "2" && arrlist[0].ToString() == "1") && (userInfo.IM1Account.Trim() != ""||userInfo.IM2Account.Trim() != ""||userInfo.IM3Account.Trim() != ""||userInfo.IM4Account.Trim() != ""||userInfo.IM5Account.Trim() != ""||userInfo.IM6Account.Trim() != ""))
            {
                IsAgreeContInfo = true;
            }
            this.DynamicTitle = GetText("{0}: speak {1}, learn {2} for language exchange - italki", new string[] { userInfo.Nickname, GetLanguageText(userInfo.MotherTongue), GetLanguageText(userInfo.TargetLanguage) });
            this.DynamicKeywords = GetText("{0}, speak {1}, learn {2}, language exchage", new string[] { userInfo.Nickname, GetLanguageText(userInfo.TargetLanguage), GetLanguageText(userInfo.MotherTongue) });
            this.DynamicDescription = Lx.Web.Common.UI.Globals.GetString(userInfo.Introduction, 200);
            base.OnLoad(e);
        }
        protected String GetUserLastEventDescrip(String CateId, String VarReplace)
        {

            if (CateId != null && VarReplace != null)
            {
                String[] StrArray = VarReplace.Split('\n');
                if (StrArray != null)
                {
                    return GetText(CateId.Trim(), StrArray);
                }
                else
                {
                    return "";
                }
            }
            return "";
        }
   

    }
}
